/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.thienloc.omap.session;

import com.thienloc.omap.entity.KetResult;
import java.util.List;
import org.slf4j.LoggerFactory;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

/**
 *
 * @author GiangLT
 */
@Stateless
public class KetResultFacade extends AbstractFacade<KetResult> {

    @PersistenceContext(unitName = "omapPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public KetResultFacade() {
        super(KetResult.class);
    }

    public List<KetResult> findByMaTinh(String maTinh) {
        try {
            TypedQuery<KetResult> q = em.createNamedQuery("KetResult.findByMaTinh", KetResult.class);
            q.setParameter("maTinh", maTinh);
            List<KetResult> result = q.getResultList();
            return result;
        } catch (NoResultException ex) {
            return null;
        } catch (Exception ex) {
            LoggerFactory.getLogger(KetResultFacade.class.getName()).error("", ex);
            return null;
        }
    }
}
